import { App, Plugin } from "vue";

import { onResize } from "@/utils/resize-util";

/** 监听插件 */
export default <Plugin<any[]>>{
  install: function (app: App) {
    // 全局指令
    app.directive("resize", (el, binding) => {
      if (typeof binding.value !== "function") {
        throw new Error("v-resize 绑定值必须为 function");
      }
      onResize(el, binding.value);
    });
    // 方法
    app.config.globalProperties.$onResize = onResize;
  }
}

declare module "@vue/runtime-core" {
  interface ComponentCustomProperties {
    $onResize: typeof onResize;
  }
}
